package com.wingsoft.framework.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.wingsoft.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 描述
 *
 * @author jiangjiao
 * @date 2025-09-22
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "createBy", SecurityUtils::getUsernameSafe, String.class);
        this.strictInsertFill(metaObject, "updateBy", SecurityUtils::getUsernameSafe, String.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date::new, Date.class);
        this.strictUpdateFill(metaObject, "updateBy", SecurityUtils::getUsernameSafe, String.class);
    }
}
